<?php  
 ini_set("display_errors",0);
require_once('pr_yearly_income_pajak.php');
	
my_component_load('testing' , false);
my_component_load('paging' , false);   
my_component_load('data_setting', false);
my_component_load('list_kalender' , false);   
my_component_load('pr_yearly_income' );
$task = isset($_GET['task']) ? $_GET['task'] : "";  
$tanggal = isset($_GET['tanggal']) ? $_GET['tanggal'] : "";  
$value = isset($_GET['value']) ? $_GET['value'] : "";  
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;
$pr_yearly_income_id= isset( $_GET['pr_yearly_income_id'] ) ? $_GET['pr_yearly_income_id']:  0;
$komponen_id = isset( $_GET['komponen_id'] ) ? $_GET['komponen_id']:  0;
$karyawan_id = isset( $_GET['karyawan_id'] ) ? $_GET['karyawan_id']:  0;
 
$modulname = "Penggajian _BN_ Transaksi Yearly Income";
if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){
		case "edit_page":
			$validatepost = pr_yearly_income_validate();
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= form_pr_yearly_income();
				generate_my_web($content,"","plain.php");
				exit; 
			}else {
				submit_pr_yearly_income(); 
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			}
			break; 	
		case "edit_upload_page":
			$validatepost = edit_upload_validate($pr_yearly_income_id, $komponen_id, $karyawan_id);
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= form_edit_upload($pr_yearly_income_id, $komponen_id, $karyawan_id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else {
				submit_edit_upload($pr_yearly_income_id, $komponen_id, $karyawan_id);
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			}
			break; 	
		case "upload_page":
			$validatepost = upload_form_validate($pr_yearly_income_id, $komponen_id);
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= upload_form_page($pr_yearly_income_id, $komponen_id);
				generate_my_web($content, "" , 'plain.php' );
				exit;
			}else{
				upload_form_page_submit($pr_yearly_income_id, $komponen_id);
				my_direct('index.php?com='.$_GET['com'].'&task=display_upload&pr_yearly_income_id='.$pr_yearly_income_id.'&komponen_id='.$komponen_id);
			}
			break;
		case "display_upload":
			$query = "DELETE FROM pr_yearly_income_upload WHERE pr_yearly_income_id={$pr_yearly_income_id} 
				AND komponen_id={$komponen_id} ";
			my_query($query);	
			$query = "INSERT INTO pr_yearly_income_upload 
			(SELECT karyawan_id,".$pr_yearly_income_id.",".$komponen_id.",nominal FROM pr_yearly_income_temp)"	;
			my_query($query);	
			$content= "Update";
			generate_my_web($content, "" , 'plain.php' );
			exit;
			break;	
		case "create_exception_page":
			$validatepost = exception_validate($pr_yearly_income_id, $komponen_id, $id);
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= form_yearly_exception($pr_yearly_income_id, $komponen_id, $id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else {
				exception_submit($pr_yearly_income_id, $komponen_id, $id); 
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			}
			break; 	
	}
else: 
	if($task == "edit"){ 
		$pagename = "Tambah Data";
		facebox_page('index.php?com=pr_yearly_income&task=edit_page', $pagename , 260	);
	}elseif($task == "yearly_pajak_excel"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=yearly_income_pajak_".rand().".xls");
		echo pajak_excel_report($pr_yearly_income_id);
		exit;
	}elseif($task == "edit_page"){
		ini_set("max_execution_time","10000");	
		$content = form_pr_yearly_income();
		generate_my_web($content, '' ,"plain.php");
		exit;			
	}elseif($task == 'delete'){ 
		delete_pr_yearly_income($id);
		my_direct('index.php?com=pr_yearly_income');
		
	}elseif($task =="list_komponen"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Komponen";
		$view =  list_komponen($pr_yearly_income_id);
		
	}elseif($task =="list_karyawan"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Karyawan";
		$view =  list_karyawan($pr_yearly_income_id);
							
	}elseif($task =="list_karyawan_komponen"){
	 
		load_facebox_script();
		$pagename = $modulname." _BN_ Komponen per Karyawan";
		$view =  list_karyawan_komponen($pr_yearly_income_id, $karyawan_id);
	}elseif($task =="list_karyawan_pajak"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Pajak per Karyawan";
		$view =  list_karyawan_pajak($pr_yearly_income_id, $karyawan_id);
							
	}elseif($task =='loadpage'){
		$title="Proses Yearly Income";
		facebox_page('index.php?com='.$_GET['com'].'&pr_yearly_income_id='.$pr_yearly_income_id.'&task=vpage&p='.rand(0,999999) , $title , 120	); 
	}elseif($task =='vpage'){
		$content = page_kalkulasi_pr_yearly_income(); 
		generate_my_web($content,"","plain.php");
		exit;
	}elseif($task == 'proses'){ 
		update_pr_yearly_income_karyawan($pr_yearly_income_id) ;
		echo button_icon( 'check2.png' ,'')."<br/>Done !!";
		exit;
	}elseif($task == 'unproses'){ 
		$query = "UPDATE pr_yearly_income SET proses='T' WHERE pr_yearly_income_id={$pr_yearly_income_id}";
		my_query($query);	
		my_direct($_SERVER['HTTP_REFERER']);
		
	}elseif($task =="list_upload"){
			load_facebox_script();
			$pagename = $modulname." _BN_ Upload";
			$view =  list_upload($pr_yearly_income_id, $komponen_id);
	}elseif($task == 'upload'){ 
		facebox_page( 'index.php?com='.$_GET['com'].'&task=upload_page
			&pr_yearly_income_id='.$pr_yearly_income_id.'
			&komponen_id='.$komponen_id
			, "Upload Data".get_komponen($pr_yearly_income_id,$komponen_id),200);
	}elseif($task == 'upload_page'){
		$view = upload_form_page($pr_yearly_income_id, $komponen_id );
		generate_my_web($view, $pagename ,"plain.php");
		exit;
	}elseif($task == "display_upload"){ 
		$content =display_upload($pr_yearly_income_id, $komponen_id);
		generate_my_web($content, "" , 'plain.php' );
		exit; 		
		
	}elseif($task == 'upload_reset'){
		$query = "DELETE FROM pr_yearly_income_upload WHERE pr_yearly_income_id={$pr_yearly_income_id} 
			AND komponen_id={$komponen_id} ";
		my_query($query);	
		my_direct($_SERVER['HTTP_REFERER']);
		
	}elseif($task == "edit_upload"){
		$title= ($id > '0' ) ?  "Perubahan Data" : "Tambah Data";
		facebox_page('index.php?com=pr_yearly_income&task=edit_upload_page
			&pr_yearly_income_id='.$pr_yearly_income_id.'
			&komponen_id='.$komponen_id.'
			&karyawan_id='.$karyawan_id , $title , 170	); 
	}elseif($task =="edit_upload_page"){
		$content = form_upload_create($pr_yearly_income_id, $komponen_id, $karyawan_id);
		generate_my_web($content, "" , 'plain.php' );
		exit;		
			
	}elseif($task == 'upload_delete'){
		$query = "DELETE FROM pr_yearly_income_upload WHERE pr_yearly_income_id={$pr_yearly_income_id} 
			AND komponen_id={$komponen_id} 
			AND karyawan_id={$karyawan_id} ";
		my_query($query);	
		my_direct($_SERVER['HTTP_REFERER']);
		
	}elseif($task =="list_exception"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Exception";
		$view =  list_exception($pr_yearly_income_id, $komponen_id);
	}elseif($task == "create_exception"){ 
		$pagename =  $modulname." _BN_ ".($id > '0' ) ?  "Perubahan Data" : "Tambah Data";
		facebox_page('index.php?com=pr_yearly_income&task=create_exception_page
			&pr_yearly_income_id='.$pr_yearly_income_id.'
			&komponen_id='.$komponen_id.'
			&id='.$id , $title , 170	); 		
	}elseif($task == "create_exception_page"){
		$content = form_yearly_exception($pr_yearly_income_id, $komponen_id, $id);
		generate_my_web($content, '' ,"plain.php");
		exit;			
	}elseif($task == 'exception_delete'){ 
		$query = "DELETE FROM pr_yearly_income_exception WHERE yearly_income_exception_id={$id}";
		my_query($query);	
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == "excel"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=yearly_income".rand().".xls");
		echo excel_report($pr_yearly_income_id);
		exit;			
						
	}else{
		$pagename = $modulname;
		load_facebox_script();
		$view =  list_pr_yearly_income();
		$href = 'index.php?com=pr_yearly_income&task=create' ;
	}
	generate_my_web($view , $pagename );	
endif; 

